package com.ruoyi.project.system.moneydetail.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.moneydetail.domain.UsersMoneydetail;
import com.ruoyi.project.system.moneydetail.service.IUsersMoneydetailService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 消费记录Controller
 * 
 * @author ruoyi
 * @date 2023-03-01
 */
@Controller
@RequestMapping("/system/moneydetail")
public class UsersMoneydetailController extends BaseController
{
    private String prefix = "system/moneydetail";

    @Autowired
    private IUsersMoneydetailService usersMoneydetailService;

    @RequiresPermissions("system:moneydetail:view")
    @GetMapping()
    public String moneydetail()
    {
        return prefix + "/moneydetail";
    }

    /**
     * 查询消费记录列表
     */
    @RequiresPermissions("system:moneydetail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UsersMoneydetail usersMoneydetail)
    {
        Long userId=getUserId();
        if(getSysUser().isAdmin()==false){
            usersMoneydetail.setUserId(userId);
        }
        startPage();
        List<UsersMoneydetail> list = usersMoneydetailService.selectUsersMoneydetailList(usersMoneydetail);
        return getDataTable(list);
    }

    /**
     * 导出消费记录列表
     */
    @RequiresPermissions("system:moneydetail:export")
    @Log(title = "消费记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UsersMoneydetail usersMoneydetail)
    {
        List<UsersMoneydetail> list = usersMoneydetailService.selectUsersMoneydetailList(usersMoneydetail);
        ExcelUtil<UsersMoneydetail> util = new ExcelUtil<UsersMoneydetail>(UsersMoneydetail.class);
        return util.exportExcel(list, "消费记录数据");
    }

    /**
     * 新增消费记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存消费记录
     */
    @RequiresPermissions("system:moneydetail:add")
    @Log(title = "消费记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UsersMoneydetail usersMoneydetail)
    {
        return toAjax(usersMoneydetailService.insertUsersMoneydetail(usersMoneydetail));
    }

    /**
     * 修改消费记录
     */
    @RequiresPermissions("system:moneydetail:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        UsersMoneydetail usersMoneydetail = usersMoneydetailService.selectUsersMoneydetailById(id);
        mmap.put("usersMoneydetail", usersMoneydetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存消费记录
     */
    @RequiresPermissions("system:moneydetail:edit")
    @Log(title = "消费记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UsersMoneydetail usersMoneydetail)
    {
        return toAjax(usersMoneydetailService.updateUsersMoneydetail(usersMoneydetail));
    }

    /**
     * 删除消费记录
     */
    @RequiresPermissions("system:moneydetail:remove")
    @Log(title = "消费记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(usersMoneydetailService.deleteUsersMoneydetailByIds(ids));
    }
}
